<!--
 * @Author: your name
 * @Date: 2022-02-24 10:11:49
 * @LastEditTime: 2022-02-24 10:21:52
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \briup-study\day04\水平垂直居中.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>水平垂直居中</title>
    <style>
        /* 实现水平垂直居中
        1、子元素绝对定位，父元素相对定位，并且给
        子元素设置定位属性全部为0 margin为auto
        2、子元素绝对定位，父元素相对定位
        并且给子元素设置定位属性
            top: 50%;
            left: 50%;
            margin-top: -50px;
            margin-left: -50px;*/
        .parent{
            width: 200px;
            height: 200px;
            background-color: red;
            position: relative;
        }
        .child{
            width: 100px;
            height: 100px;
            background-color: pink;
          /*   position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            margin: auto; */
            /* 方案二 */
            position: absolute;
            top: 50%;
            left: 50%;
            margin-top: -50px;
            margin-left: -50px;
        }
    </style>
</head>
<body>
    <div class="parent">
        <div class="child"></div>
    </div>
</body>
</html>